﻿/*
对称素数 
Time Limit:1000MS  Memory Limit:32768K


Description:
统计输入的整数中有多少个对称素数。

Input:
输入数据中含有一些随机整数n（1＜n＜10^8）。 
Output:
统计一共读入了多少个对称素数，并予以输出。 
Sample Input:
15
11 313
Sample Output:
2
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	vector<unsigned> nums;
	nums.reserve(256);
	for (unsigned num; cin>>num; )
	{
		unsigned result=0;
		for (unsigned tmp=num; tmp;)
		{
			result=result*10+tmp%10;
			tmp/=10;
		}
		if(result==num)
			nums.push_back(num);
	}
	if(0==nums.size())
		return EXIT_FAILURE;

	unsigned maximum=*max_element(nums.begin(), nums.end());
	
	vector<unsigned> primes;
	primes.push_back(2);
	primes.push_back(3);
	primes.push_back(5);
	
	int integer=5;
	int gap=2;
	while (integer<=maximum)//
	{
		integer+=gap;
		gap=6-gap;
		bool is_prime=true;
		for (int i=2; primes[i]*primes[i]<=integer && is_prime; i++)
			if(0==integer%primes[i])
				is_prime=false;
			if(is_prime)
				primes.push_back(integer);
	}
//	copy(primes.begin(), primes.end(), ostream_iterator<unsigned>(cout, " "));
//	copy(nums.begin(), nums.end(), ostream_iterator<unsigned>(cout, " "));

	unsigned counter=0U;
	for (vector<unsigned>::iterator it=nums.begin(); it != nums.end(); ++it )
	{
		if(binary_search(primes.begin(), primes.end(), *it) )
			++counter;
	}
	cout<<counter<<endl;

	return EXIT_SUCCESS;
}